package cn.kpt.search.controller;

import cn.kpt.beans.dto.Dto;
import cn.kpt.beans.vo.hotel.SearchHotCityVO;
import cn.kpt.beans.vo.hotel.SearchHotelVO;
import cn.kpt.search.entity.HotelSearchVO;
import cn.kpt.search.service.SearchHotelService;
import cn.kpt.utils.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(value = "API")
@RestController
@RequestMapping("/api/hotellist")
public class SearchHotelController {

    @Resource
    private SearchHotelService searchHotelService;

    /**
     * 酒店模块-酒店列表
     * @param vo
     * @return
     */
    @ApiOperation(value = "查询酒店分页",httpMethod = "POST",
            protocols = "HTTP",produces = "application/json",
            response = Dto.class,notes = "查询酒店分页（用于查询酒店列表）" +
            "<p>成功：success=‘true’ | 失败：success = ‘false’ 并返回错误代码，如下：</p>" +
            "<p>错误代码：</p>" +
            "<p>20001：系统异常，获取失败</p>" +
            "<p>目的地不能为空</p>")
    @RequestMapping(value = "/searchItripHotelPage",method = RequestMethod.POST)
    public Dto searchItripHotelPage(@RequestBody SearchHotelVO vo){
        try {
            // 表单验证
            if(EmptyUtils.isEmpty(vo.getDestination())){
                return DtoUtil.returnFail("目的地不能为空！", ErrorCode.SEARCH_PARAMETER_ERROR);
            }
            Page<HotelSearchVO> page = new Page<>();
            page.setPageSize(vo.getPageSize() == null ? Constants.DEFAULT_PAGE_SIZE : vo.getPageSize());
            page.setCurPage(vo.getPageNo()  == null ? Constants.DEFAULT_PAGE_NO : vo.getPageNo());
            searchHotelService.searchHotelListForPaging(page,vo);
            return DtoUtil.returnDataSuccess(page);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败！", ErrorCode.SEARCH_UNKNOWN);
        }
    }

    /**
     *酒店模块（首页推荐 ）
     * @param vo
     * @return
     */
    @ApiOperation(value = "根据热门城市查询酒店",httpMethod = "POST",
            protocols = "HTTP",produces = "application/json",
            response = Dto.class,notes = "根据热门城市查询酒店" +
            "<p>成功：success=‘true’ | 失败：success = ‘false’ 并返回错误代码，如下：</p>" +
            "<p>错误代码：</p>" +
            "<p>20003：系统异常，获取失败</p>" +
            "<p>20004：城市id不能为空</p>")
    @RequestMapping(value = "/searchItripHotelListByHotCity",method = RequestMethod.POST)
    public Dto searchItripHotelListByHotCity(@RequestBody SearchHotCityVO vo){
        try {
            // 表单验证
            if(EmptyUtils.isEmpty(vo.getCityId()) || EmptyUtils.isEmpty(vo.getCount())){
                return DtoUtil.returnFail("参数错误！", ErrorCode.SEARCH_PARAMETER_ERROR);
            }
            List<HotelSearchVO> voList = searchHotelService.searchHotelListByHotCity(vo);
            return DtoUtil.returnDataSuccess(voList);
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败！", ErrorCode.SEARCH_UNKNOWN);
        }
    }
}
